# 导包
from api.login import LoginAPI
from api.dept import DeptAPI
import config
from common.assertutil import common_assert
from common.jsonutil import build_data
import pytest


# 创建测试类
class TestLoginAPI:
    # 初始化
    token666 = None

    # 前置处理
    def setup_class(self):
        # 实例化接口类
        self.login_api = LoginAPI()
        self.dept_api = DeptAPI()

        # 登录成功
        response = self.login_api.login(config.login_data)
        TestLoginAPI.token666 = response.json().get("data")
        print(TestLoginAPI.token666)

    # 创建部门
    @pytest.mark.parametrize("dept_data, status_code, success, code, message", build_data(f"{config.BASE_PATH}/data/dept.json"))
    def test_insert_dept(self, dept_data, status_code, success, code, message):
        response = self.dept_api.insert_dept(TestLoginAPI.token666, dept_data)
        print(response.json())
        # 断言
        common_assert(response, status_code, success, code, message)
